Parallel sessions allows you to run multiple instance of server virtually while running only one server. This is helpful when you are running multiple test cases which access the same routes but different variants as parallel sessions allow you to set different variants on same routes without conflicting. This saves CPU and RAM both as only one server is running instead of multiple.
To add parallel sessions, modify run-mock-server-console.js to add 'sessions' parameter.
require('./endpoints');
var midway = require('testarmada-midway');
midway.start({
host: "localhost",
mockedDirectory: "./resources/mocked-data",
port: 8000,
sessions: 2,
project: 'HelloMidway'
});
You can also start or add sessions via command line argument
node resources/run-mock-server-console.js --midwaySessions 2
If you pass sessions = 2, there will be two parallel sessions along with one default session.
Register Session To register sessions to be used
var sessionId = midway.registerSession();
Get Sessions To get all the active sessions
var activeSessions = midway.getSessions();
Check Session To check the session status (Available or In-Use or invalid)
var sessionStatus = midway.checkSession(sessionId);
Close Session To de-register session for later use
var closeSession = midway.closeSession(sessionId);
To use a parallel session call the following api:
curl http://localhost:8000/_admin/api/midway/registerSession
or
midway.registerSession()
and a session id will be returned.
Append this sessionId to the mocked host address to use this parallel session. For ex: If your mock host server is http://localhost:8080 and your session id is 112233
then the mock server address for this parallel session will be http://localhost:8080/112233.
Start mock server with two sessions. Now go to the 'Message' route. You will see three routes for message, default and two for parallel sessions that you just added. Now for each route choose a different variant and hit the URL icon. You will see that each time you will get a different value though you are hitting the same route.
Try to go through Midway UI to understand sessions.